package Persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author kenneth
 */
public class DatabaseConnection {
    
    private final String url = "jdbc:mysql://kennero87.eightyseven.axc.nl:3306/";
    private final String dbName = "kennero87_datacom";
    private final String driver = "com.mysql.jdbc.Driver";
    private final String userName = "kennero87_user";
    private final String password = "datacomproject";
    
    private Connection connection;
    
    public void openConnection() {
        try {
          Class.forName(driver).newInstance();
          connection = DriverManager.getConnection(url+dbName,userName,password);          
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public ResultSet executeQuery(String query) throws SQLException {
        Statement statement = connection.createStatement();
        return statement.executeQuery(query);
    }
    
    public int executeUpdate(String query) throws SQLException {
        Statement statement = connection.createStatement();
        return statement.executeUpdate(query);
    }
    
    public void closeConnection() {
        try {
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
